package com.baozhun.mall.common.widget.viewpager


import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.annotation.Nullable
import androidx.viewpager.widget.ViewPager

/**
 * @Title：自定义不可滑动viewPage
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2024/3/26
 * @Version：1.0.0
 */
class NoScrollViewPager : ViewPager {
    //true  是不可滑动    false  是可滑动
    private var noScroll = false

    constructor(context: Context) : super(context)
    constructor(context: Context, @Nullable attrs: AttributeSet?) : super(context, attrs)

    public fun setNoScroll(noScroll: Boolean) {
        this.noScroll = noScroll
    }

    override fun scrollTo(x: Int, y: Int) {
        super.scrollTo(x, y)
    }

    override fun onTouchEvent(ev: MotionEvent): Boolean {
        return if (noScroll) false else super.onTouchEvent(ev)
    }

    override fun onInterceptTouchEvent(arg0: MotionEvent): Boolean {
        return if (noScroll) false else super.onInterceptTouchEvent(arg0)
    }

    override fun setCurrentItem(item: Int, smoothScroll: Boolean) {
        super.setCurrentItem(item, smoothScroll)
    }

    override fun setCurrentItem(item: Int) {
        super.setCurrentItem(item)
    }
}